home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 2.8 KB | 110 lines | [TEXT/MPS ] |
- (*
- CTBRecvChars([n[,dontStrip]]) -- Receive n characters, waiting until they're available if necessary.
- Default to all available characters. If the second parameter is present, then don't do control
- character and top bit stripping.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w CTBRecvChars.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=2752 -sn Main=CTBRecvChars ∂
- CTBRecvChars.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 2/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S CTBRecvChars } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure CTBRecvChars(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- CTBRecvChars(paramPtr);
- end;
-
- procedure CTBRecvChars(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- var toRead, haveRead: longInt;
- l: longInt;
- h: Handle;
- p: Ptr;
- theBuf: InputBufferHandle;
- sizes: CMBufferSizes;
- status: CMStatFlags;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(CTBRecvChars);
- end;
-
- begin
- { Check the parameter count. }
- if paramPtr^.paramCount > 2 then Fail('Invalid parameter count');
-
- { Check that the Comm Toolbox is ready. }
- CTBReady;
- { And that we have a connection tool. }
- EnsurePresent(connectionTool);
- { And that it's open. }
- EnsureOpen;
- { Get the input buffer. }
- theBuf := InputBufferHandle(CMGetUserData(Globals^^.connHand));
- { Drop any old termination information. }
- if theBuf^^.termString <> nil then
- begin
- DisposHandle(theBuf^^.termString);
- theBuf^^.termString := nil;
- theBuf^^.timeOut := -1;
- end;
-
- { Figure out how much to read. }
- if ParmPresent(1) then toRead := GetLongParm(1)
- else if CMStatus(Globals^^.connHand,sizes,status) = noErr then
- toRead := sizes[cmDataIn]+theBuf^^.amountLeft
- else toRead:= theBuf^^.amountLeft;
-
- { Allocate a handle for it. }
- h := NewHandle(toRead);
- if h = nil then Fail('Out of memory');
- haveRead := 0;
- if toRead > 0 then
- begin
- HLock(h);
- { First get the stuff in the input buffer. }
- haveRead := min(toRead,theBuf^^.amountLeft);
- if haveRead > 0 then
- begin
- BlockMove(theBuf^^.bufferPtr,h^,haveRead);
- theBuf^^.amountLeft := theBuf^^.amountLeft - haveRead;
- toRead := toRead - haveRead;
- end;
- { Then go to the outside for the rest. }
- if toRead > 0 then haveRead := haveRead + ReadFromConn(Ptr(ord4(h^)+haveRead),toRead);
- HUnlock(h);
- end;
-
- { Strip and return the results. }
- StripBytes(h,haveRead,not ParmPresent(2));
-
- paramPtr^.returnValue := h;
- end;
-
- end.
-